<?php
/**
 * Created by PhpStorm.
 * User: 1
 * Date: 2016-11-28
 * Time: 16:31
 */

namespace app\src\shoppingCart\action;


use app\src\base\action\BaseAction;
use app\src\base\helper\ValidateHelper;
use app\src\goods\helper\PriceHelper;
use app\src\goods\logic\ProductSkuLogic;
use app\src\shoppingCart\logic\ShoppingCartLogic;

class ShoppingCartUpdateAction extends BaseAction
{
    public function update($id,$cnt,$uid){
        $logic = new ShoppingCartLogic();
        $result = $logic->getInfo(['id'=>$id,'uid'=>$uid]);

        if(!ValidateHelper::legalArrayResult($result)){
            return $this->error(lang('err_not_find'));
        }
        
        $cart = $result['info'];
        $psku_id = $cart['psku_id'];

        $result = (new ProductSkuLogic())->getInfo(['id'=>$psku_id]);

        if(!ValidateHelper::legalArrayResult($result)){
            return $this->error(lang('err_not_find'));
        }
        
        $sku = $result['info'];

        $price = PriceHelper::getSkuPrice($sku,$cnt);

        $result = $logic->save(['id'=>$id,'uid'=>$uid],['count'=>$cnt,'price'=>$price]);
        
        return $result;
    }
}